﻿using System;
using System.Web.UI.WebControls;
using Fjaspx.Sys.Bll;
using Fjaspx.Common;

namespace Fjaspx.UI.Web
{
    public partial class TEACHER_admin : System.Web.UI.Page
    {
        private int _pages;
        public int pages
        {
            set { _pages = value; }
            get { return _pages; }
        }
        Fjaspx.Sys.Bll.ROYcms_Enterprise Bll = new Fjaspx.Sys.Bll.ROYcms_Enterprise();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                SystemCms.AdminSesion();

                Bind("");
                switch (Request["t"])
                {
                    case "del":
                        del(Convert.ToInt32(Request["bh"]));
                        Bind("");
                        break;
                    case "tj":
                        tj(Convert.ToInt32(Request["bh"]));
                        Bind("");
                        break;
                    case "on":
                        ON(Convert.ToInt32(Request["bh"]));
                        Bind("");
                        break;
                }
            }

        }

        void Bind(string classs)
        {

            int page = 0;
            string where = "";
            if (Request["page"] != null)
            {
                page = Convert.ToInt32(Request["page"]) - 1;
            }
            if (classs != "")
            {
                where = " classname =" + classs;
            }
            //if (where != "")
            //{
            //    where = where + " and type = 'Enterprise' ";
            //}
            //else { where = " type = 'Enterprise' "; }
            //if (Request["orderby"] != "")
            //{

            //}
            where += " bh > 0 ";

            ROYcms_Enterprise Bll = new ROYcms_Enterprise();
            pages = Bll.GetCount(where) / 30 + 1; //分页的总数          
            PagedDataSource pg = new PagedDataSource();
            pg.DataSource = Bll.GetList(where+" order by bh desc ").Tables[0].DefaultView;
            pg.AllowPaging = true;
            pg.PageSize = 30;
            pg.CurrentPageIndex = page;
            Repeater_Enterprise_admin.DataSource = pg;
            Repeater_Enterprise_admin.DataBind();


        }



        void del(int bh)
        {
            Bll.Delete(bh); 
        }
        void tj(int bh)
        {
            Bll.Tuijian_Enterprise(bh);
        }
        void ON(int bh)
        {
            Bll.on_Enterprise(bh);
        }

        protected void ImageButton_all_del_Click(object sender, System.Web.UI.ImageClickEventArgs e)
        {
            //批量删除
            int nub = 0;
            for (int i = 0; i < Repeater_Enterprise_admin.Items.Count; i++)
            {
                int id = Convert.ToInt32(((Label)Repeater_Enterprise_admin.Items[i].FindControl("Label_id")).Text);
                CheckBox CK = (CheckBox)Repeater_Enterprise_admin.Items[i].FindControl("ID_list");
                if (CK.Checked)
                {
                    del(id);
                    nub += 1;
                }
            }
            Response.Redirect("/administrator/Message.aspx?message=批量删除<b>" + nub + "</b>条信息成功！&z=yes");
        }
        protected void ImageButton_ding_Click(object sender, System.Web.UI.ImageClickEventArgs e)
        {
            //批量推荐
            int nub = 0;
            for (int i = 0; i < Repeater_Enterprise_admin.Items.Count; i++)
            {
                int id = Convert.ToInt32(((Label)Repeater_Enterprise_admin.Items[i].FindControl("Label_id")).Text);
                CheckBox CK = (CheckBox)Repeater_Enterprise_admin.Items[i].FindControl("ID_list");
                if (CK.Checked)
                {
                    tj(id);
                    nub += 1;
                }
            }
            Response.Redirect("/administrator/Message.aspx?message=批量推荐<b>" + nub + "</b>条信息成功！&z=yes");
        }
        protected void ImageButton_K_Click(object sender, System.Web.UI.ImageClickEventArgs e)
        {
            //批量验证
            int nub = 0;
            for (int i = 0; i < Repeater_Enterprise_admin.Items.Count; i++)
            {
                int id = Convert.ToInt32(((Label)Repeater_Enterprise_admin.Items[i].FindControl("Label_id")).Text);
                CheckBox CK = (CheckBox)Repeater_Enterprise_admin.Items[i].FindControl("ID_list");
                if (CK.Checked)
                {
                    ON(id);
                    nub += 1;
                }
            }
            Response.Redirect("/administrator/Message.aspx?message=批量验证<b>" + nub + "</b>条信息成功！&z=yes");
        }



    }
}
